#ifndef CARFACTORY_H
#define CARFACTORY_H

#include "ObjectPool.h"
#include "SedanCar.h"
#include "CoupeCar.h"
#include "MiniCar.h"

#include <cstdint>
#include <string>

class Car;
class SedanCar;
class CoupeCar;
class MiniCar;

class CarFactory
{
public:
	CarFactory(uint32_t initialPoolSize, uint32_t maxPoolSize) : m_sedanCarPool(initialPoolSize, maxPoolSize)
		, m_coupeCarPool(initialPoolSize, maxPoolSize), m_miniCarPool(initialPoolSize, maxPoolSize) {}
	~CarFactory() {}

	Car* getCar(std::string carType) {
		Car *car;
		if (carType == "Sedan") {
			car = m_sedanCarPool.getObject();
		} else if (carType == "Coupe") {
			car = m_coupeCarPool.getObject();
		} else if (carType == "Mini") {
			car = m_miniCarPool.getObject();
		} else {
			// default
			car = m_sedanCarPool.getObject();
		}
		return car;
	}

	void releaseCar(Car *car) {
		std::string carType = car->type();
		if (carType == "Sedan") {
			m_sedanCarPool.releaseObject(static_cast<SedanCar*>(car));
		} else if (carType == "Coupe") {
			m_coupeCarPool.releaseObject(static_cast<CoupeCar*>(car));
		} else if (carType == "Mini") {
			m_miniCarPool.releaseObject(static_cast<MiniCar*>(car));
		}
	}

private:
	ObjectPool<SedanCar> m_sedanCarPool;
	ObjectPool<CoupeCar> m_coupeCarPool;
	ObjectPool<MiniCar> m_miniCarPool;

};

#endif